package com.prs.crm.action.document;

import java.io.File;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;

import com.prs.crm.domain.document.FileView;
import com.prs.crm.service.document.FileViewService;
import com.prs.ftpserver.main.FtpMain;

/**
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * 
 * @author JohnLan E-mail:JohnMr.Lan@foxmail.com
 * @version 创建时间：2012-7-19 上午09:42:20
 * 
 *          类说明
 */

public class FileViewAction extends BaseAction {

	private FileView fileView;

	private FileViewService fileViewService;

	private PaginationSupport pagination;

	private String files;

	public List<File> file;

	private FtpMain ftpServer;

	@Action("edituploadFile")
	public String editFile() {
		return SUCCESS;
	}

	@Action(value = "uploadFile", results = {
			@Result(name = "success", type = "redirect", location = "edituploadFile"),
			@Result(name = "error", type = "chain", location = "edituploadFile") })
	public String uploadFile() {
	
		System.out.println("files:" + files);

		File filer=new File(files);
		boolean upstate=getFtpServer().uploadFile(files,filer.getName());
		FileView  fileView=new FileView();
		fileView.setFileformat("doc");
		fileView.setFileName(filer.getName());
		fileView.setFileType("一般文档");
		
      this.getFileViewService().save(fileView);
		
		return SUCCESS;
	}

	public FileView getFileView() {
		return fileView;
	}

	public void setFileView(FileView fileView) {
		this.fileView = fileView;
	}

	public FileViewService getFileViewService() {
		return fileViewService;
	}

	public void setFileViewService(FileViewService fileViewService) {
		this.fileViewService = fileViewService;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public String getFiles() {
		return files;
	}

	public void setFiles(String files) {
		this.files = files;
	}

	public FtpMain getFtpServer() {
		if (ftpServer == null) {
			ftpServer = new FtpMain();
		}
		return ftpServer;
	}

	public void setFtpServer(FtpMain ftpServer) {
		this.ftpServer = ftpServer;
	}

	public List<File> getFile() {
		return file;
	}

	public void setFile(List<File> file) {
		this.file = file;
	}

	

}
